<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 找到所有好下标 -->
    <script>
      var goodIndices = function (a, k) {
        var l = [],
          i,
          j
        a: for (i = k; i < a.length - k; ++i) {
          for (j = i; --j > i - k; ) if (a[j - 1] < a[j]) continue a
          for (j = i; ++j < i + k; ) if (a[j] > a[j + 1]) continue a
          l.push(i)
        }
        return l
      }
      console.log(goodIndices([2, 1, 1, 1, 3, 4, 1], 2))
    </script>
  </body>
</html>
